<script type="text/javascript">
var withDrawState = 0;
var is_refresh = 0;

function show_withdraw(id,money,state)
{
	$("#spanWithDrawMoney").html(money);
	$("#spanWithDrawMoney2").html(money);
	$("#divWithDrawMoney").html(money);
	$("#withDrawId").html(id);

	withDrawState = state;
	$("#divWithDraw").show();
}

function close_withdraw()
{	
	$("#spanWithDrawMoney").html("");
	$("#spanWithDrawMoney2").html("");
	$("#divWithDrawMoney").html("");
	$("#withDrawId").html("");
	$("#txtSubmitWithDrawMoney").val("");

	withDrawState = 0;
	$("#divWithDraw").hide();

	if(is_refresh == 1)
	{
		document.location.reload();
	}
}

function pices(o)
{
	var pice = o.replace(/^[0-9]+\.?[0-9]{0,9}$/ ,'');//可限制输入位数
	if(pice.length>0)
	{
		o.value = "";
		return false;
	}
	return true;
}

/**
 * 	撤消提交
 */
function canel_withdraw(id)
{
	var con = confirm("确定要撤消该退款吗？");
	if(con == true)
	{
		jQuery.ajax({
            type: "POST",
            url: "/member/canelwithdraw/",
            data: {"id":id},
            dataType:"json",
            success: function(obj){
            	if(obj.ret == 1)
    			{
    				alert("提交成功");
    				document.location.reload();
    			}
    			else
    			{
        			//失败				
    				alert("提交失败");
    			}
            }
        });
	}
}

/**
 * 	确认退款
 	state:类型：1：完成 =>退款；5：申请退款 =>[撤消]；15：退款失败=>退款
 */
function submitwithdraw()
{
 	var state = withDrawState;
	var max_withdraw = parseFloat($("#spanWithDrawMoney").html());
	var submit_withdraw = $("#txtSubmitWithDrawMoney").val();
	var id = $("#withDrawId").html();

	if(pices(submit_withdraw))
	{
		if(submit_withdraw > max_withdraw)
		{
			alert("退款金额不能大于充值金额");
			return;
		}
		
		submit_withdraw = parseFloat($("#txtSubmitWithDrawMoney").val());

		jQuery.ajax({
            type: "POST",
            url: "/member/withdraw/",
            data: {"submit_withdraw":submit_withdraw,"state":state,"logid":id},
            dataType:"json",
            success: function(obj){
            	if(obj.ret == 1)
    			{
    				//成功,设置    				
    				$("#spanWithDrawMoney2").html(submit_withdraw);
    				$("#divSubmit").hide();
    				$("#divMsg").show();

    				is_refresh = 1;
    			}
    			else
    			{//失败				
    				alert("提交失败");
    			}
            }
        });
	}
	else
	{
		alert("请输入数字金额");
	}
}


</script>

<div class="center">
	<div class="home">
		<div class="home_left">
		<?php echo $this->partial('member/menu.phtml',array('uCount' => $this->uCount,'menuId'=>$this->menuId,'user'=>$this->user,'account'=>$this->account)); ?>
		</div>
		<div class="home_right">

			<div class="weizhi">
				<h2>
					<a href="#">我的RMB帐户</a><i>&gt;</i>退款
				</h2>
			</div>
			<div class="refundtop">
				<div class="refundnum">
					<p>
						您的账户余额：<span><?php echo $this->account->money;?> </span>元
					</p>
				</div>
				<ul>
					<li>1. 退款可通过您的充值历史任意一条，其同样的方式退还到会员充值相应的账户内。</li>
					<li>2. 退款金额不能大于您选中记录的充值金额数。</li>
					<li>3. 退款由于涉及第三方支付平台，将有一个较长的处理过程，请您耐心等待。</li>
				</ul>
			</div>

			<div class="jilu">
				<div class="jilutop">
					<h2>充值记录</h2>
				</div>
				<table>
					<tr>
						<th class="j1">流水号</th>
						<th class="j2">充值时间</th>
						<th class="j3">充值方式</th>
						<th class="j4">充值金额(￥)</th>
						<th class="j5">可退金额(￥)</th>
						<th class="j6">操作</th>
					</tr>
					<?php foreach ($this->historyList as  $item){ ?>
					<tr>
						<td class="j1"><?php echo $item->Id;?></td>
						<td class="j2"><?php echo $item->DateCreated;?></td>
						<td class="j3"><?php echo $item->Source;?></td>
						<td class="j4"><?php echo number_format($item->getWidthDrawMoney(),2);?>
						</td>
						<td class="j5"><?php echo number_format($item->getWidthDrawMoney(),2);?>
						</td>
						<td class="j6"><?php
						switch((int)$item->State)
						{
							case 0:
								echo '<a class="tui" href="/member/recharge"><span>充值</span></a>';
								break;
							case 1:
								echo '<a class="tui" href="javascript:show_withdraw('.$item->Id.','.$item->getWidthDrawMoney().','.$item->State.');"><span>退款</span></a>';
								break;
							case 5:
								echo '<a class="tui" href="javascript:canel_withdraw('.$item->Id.');"><span>撤消</span></a>';
								break;
							case 10:
								echo '&nbsp;>';
								break;
							case 15:
								echo '<a class="tui" href="javascript:show_withdraw('.$item->Id.','.$item->getWidthDrawMoney().');"><span>退款</span></a>';
								break;
						}
						?>
						</td>
					</tr>
					<?php
					}?>
				</table>

				<div class="toolbar"
				<?php if(empty($this->historyList))  echo "style='display: none'"; ?>>
					<?php echo $this->partial('paging.phtml',array("pages"=>$this->history)); ?>
				</div>

				<div class="jilunwu"
				<?php if($this->history['size']) echo "style='display:none'";?>>
					<p>您至今还没有冲值记录！</p>
				</div>

				<div class="tuikuanask">
					<h2>退款常见问题：</h2>
					<ul>
						<li><a href="#">1. 如何申请退款，什么时候能收到？</a></li>
						<li><a href="#">2. 如何退款</a></li>
					</ul>
				</div>
			</div>
		</div>
	</div>
</div>


<!--退款弹出层-->
<div id="divWithDraw" class="refundstorey" style="display: none">
	<div class="refundstoreytop">
		<h1>申请退款</h1>
		<div class="refundclose">
			<a href="javascript:close_withdraw()" title="关闭">关闭</a>
		</div>
	</div>
	<div id="divSubmit" class="refundstoreynum" style="display:none;">
		<h2>
			您的帐户可退余额：<span id='spanWithDrawMoney'>100</span>元
		</h2>
		<table>
			<tbody>
				<tr>
					<td class="r">流 水 号:</td>
					<td><span id='withDrawId'>NT2011356221</span></td>
				</tr>
				<tr>
					<td class="r">充值金额:</td>
					<td><span id='divWithDrawMoney'>500元</span><span>(退款金额不能大于充值金额)</span>
					</td>
				</tr>
				<tr>
					<td class="r">退款金额:</td>
					<td><input type="text" id="txtSubmitWithDrawMoney"
						name="txtSubmitWithDrawMoney" />
						<p>元</p></td>
				</tr>
			</tbody>
		</table>
		<div class="refundwrong" style="display: none;">
			<p>此交易流水号退款限退500元，请重新输入</p>
		</div>
		<div class="refundanniu">
			<a href="javascript:submitwithdraw()"><span>确认退款</span> </a>
		</div>
	</div>
	<div id="divMsg" class="refundsus" style="display: none;">
		<i>成功</i>
		<div class="refundsusinfo">
			<h2>您成功申请了退款</h2>
			<em>退款金额：<span id='spanWithDrawMoney2'>100</span>元</em>
			<p>我们会尽快为您处理，由于涉及第三方平台，可能有一个较长的处理过程，请耐心等待。</p>
			<div class="refundanok">
				<a class="reclose" href="javascript:close_withdraw()"><span>关闭</span>
				</a><a class="fanhui" href="/member/account">返回我的RMB帐户</a>
			</div>
		</div>
	</div>
</div>
<div class="refundoverlay" style="display: none"></div>
<!--退款弹出层-->
